<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Library\PrintingOptions\PrintingOptions;
use App\Models\Invoices;
use App\Rep\EmployeeRep;
use Illuminate\Http\Request;

class Employee extends Controller
{
    //员工管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new EmployeeRep();
    }

    /**
     * 获取员工列表
     * @param Request $request
     */
    public function getEmployeeList(Request $request){
        $params = $request->all();
        $data = $this->rep->getEmployeeListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加员工
     * @param Request $request
     */
    public function createEmployee(Request $request){
        $params = $request->all();
        $data = $this->rep->createEmployeeRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    public function clearEmployeeCardId(Request $request){
        $params = $request->only(['users_ids']);
        $data = $this->rep->clearEmployeeCardIdRep($params);
        return re(0,$data,'success');
    }

    /**
     * 删除员工
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delEmployee(Request $request){
        $params = $request->all();
        $data = $this->rep->delEmployeeRep($params);
        return re($data['code']);
    }

    /**
     * 获取员工列表通过工种ID
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getEmployeeListByJobTypeID(Request $request){
        $params = $request->all();
        $data = $this->rep->getEmployeeListByJobTypeIDRep($params);
        return re(0,$data,'success');
    }

    /**
     * 员工查询可领取订单
     */
    public function searchPensionableOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->searchPensionableOrderChildRep($params);
        return re(0,$data,'success');
    }

    /**
     * 员工领取订单
     */
    public function drawOrderChild(Request $request){
        $params = $request->only(['user_id','order_id','order_second_id','order_count','job_type_id']);
        $data = $this->rep->drawOrderChildRep($params);
        //p($data);
        $order_child = $data['data']['data']->toArray();
        $count = $data['data']['count'];
        $order_child_id_arr = $data['data']['order_child_id_arr'];
        $list = Invoices::where('is_show',1)->orderBy('sort','asc')->get();

        $pritingOptions = new PrintingOptions();
        $array = $pritingOptions->getOrderInvoices($list,$order_child,$count,$order_child_id_arr);
        return re($data['code'],$array,$data['msg']);
    }

    /**
     * 提交订单
     */
    public function submitOrderChild(Request $request){
        $params = $request->only(['order_id','order_child_ids','user_id','employee_user_id']);
        $data = $this->rep->submitOrderChildRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    public function submitOrderChildByDayin(Request $request){
        $params = $request->all();
        $data = $this->rep->submitOrderChildByDayinRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }


    /**
     * 查询已完成订单
     * @param Request $request
     */
    public function searchCompletedOrUnfinishedOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->searchCompletedOrUnfinishedOrderChildRep($params);
        return re(0,$data,'success');
    }


}
